Skip to content

fix: distinguish aborted requests from timeouts with SdkErrorCode.RequestAborted - #3252

Open
Anshuman-Singhal wants to merge 1 commit into
modelcontextprotocol:mainfrom
Anshuman-Singhal:fix/request-aborted-error-code
Open

Anshuman-Singhal wants to merge 1 commit into
modelcontextprotocol:mainfrom
Anshuman-Singhal:fix/request-aborted-error-code

Conversation

@Anshuman-Singhal

Copy link
Copy Markdown

Fixes #2165

Cancelling a request via AbortSignal rejected with REQUEST_TIMEOUT, the same code as a real timeout, so callers could not tell a deliberate cancellation apart from a timeout.

This change adds a new SdkErrorCode.RequestAborted code (REQUEST_ABORTED) and a shared helper, sdkErrorForAbortReason(reason), and routes abort paths through it:

  • Protocol.request: the cancel() path and the already-aborted early path.
  • Client cache (_serveFromCache) and subscriptions/listen pre-aborted guards.
  • The multi-round-trip pacing delay (inputRequiredDriver sleep abort paths).
  • instrumentation: outcomeForError maps RequestAborted to cancelled.

An SdkError passed as the abort reason is still rethrown untouched, and a genuine timeout still rejects with REQUEST_TIMEOUT, including a timeout set with AbortSignal.timeout() (its TimeoutError reason keeps RequestTimeout).

Tests updated: abortReasonPassthrough.test.ts (old pin flipped to RequestAborted, plus an in-flight abort test and an AbortSignal.timeout() carve-out test), errorSurfacePins.test.ts (new enum member pinned), listen.test.ts, and responseCache.test.ts. Includes a changeset (client and server, patch).

Verified locally: core-internal 1861 tests pass, client 1115 tests pass, server 725 tests pass. Typecheck, eslint, and prettier are clean.

…uestAborted

Fixes modelcontextprotocol#2165. Cancelling a request via AbortSignal rejected with
REQUEST_TIMEOUT, the same code as a real timeout, so callers could not
tell a deliberate cancellation apart from a timeout. Aborts now reject
with the new REQUEST_ABORTED code, in Protocol.request, the client
cache and subscriptions/listen guards, and the multi-round-trip pacing
delay. A genuine timeout still rejects with REQUEST_TIMEOUT, including
a timeout set with AbortSignal.timeout().
@Anshuman-Singhal
Anshuman-Singhal requested a review from a team as a code owner November 29, 2026 00:25
@changeset-bot

changeset-bot Bot commented Nov 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 96288c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@modelcontextprotocol/client Patch
@modelcontextprotocol/server Patch
@modelcontextprotocol/codemod Patch
@modelcontextprotocol/core Patch
@modelcontextprotocol/server-legacy Patch
@modelcontextprotocol/core-internal Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@3252

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@3252

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@3252

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@3252

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@3252

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@3252

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@3252

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@3252

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@3252

commit: 96288c6

@claude claude Bot added the v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes label Nov 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AbortSignal cancellation throws SdkErrorCode.RequestTimeout instead of a distinct abort error

1 participant